import { Injectable } from "@nestjs/common";
import { Repository } from "typeorm";
import { RoleEntity } from "./role.entity";
import { InjectRepository } from "@nestjs/typeorm";
import { MenuService } from "../menu/menu.service";

@Injectable()
export class RoleService{
    constructor(
        @InjectRepository(RoleEntity)
        private readonly roleService:Repository<RoleEntity>,
        private menuService:MenuService
    ){}
    async find(){
        return await this.roleService.find()
    }
    async add(role){
        return await this.roleService.save(role)
    }
    async remove(roleId){
        return await this.roleService.delete(roleId)
    }
    async update(role){
        try {
            if(role.menus){
                role.roleMenus=await this.menuService.findByIds([1,2])
            }
            return await this.roleService.update(role.roleId,role)
        } catch (error) {
            console.log(error)
        }
        
    }
}